//#include <stdio.h>
//#include <unistd.h>
//#include <stdlib.h>
//int g_unval;
//int g_val = 100;
//int main(int argc, char *argv[], char *env[])
//{
// const char *str = "helloworld";
// printf("code addr: %p\n", main);
// printf("init global addr: %p\n", &g_val);
// printf("uninit global addr: %p\n", &g_unval);
// static int test = 10;
// char *heap_mem = (char*)malloc(10);
// char *heap_mem1 = (char*)malloc(10);
// char *heap_mem2 = (char*)malloc(10);
// char *heap_mem3 = (char*)malloc(10);
// printf("heap addr: %p\n", heap_mem); //heap_mem(0), &heap_mem(1)
// printf("heap addr: %p\n", heap_mem1); //heap_mem(0), &heap_mem(1)
// printf("heap addr: %p\n", heap_mem2); //heap_mem(0), &heap_mem(1)
// printf("heap addr: %p\n", heap_mem3); //heap_mem(0), &heap_mem(1)
// printf("test static addr: %p\n", &test); //heap_mem(0), &heap_mem(1)
// printf("stack addr: %p\n", &heap_mem); //heap_mem(0), &heap_mem(1)
// printf("stack addr: %p\n", &heap_mem1); //heap_mem(0), &heap_mem(1)
// printf("stack addr: %p\n", &heap_mem2); //heap_mem(0), &heap_mem(1)
// printf("stack addr: %p\n", &heap_mem3); //heap_mem(0), &heap_mem(1)
// printf("read only string addr: %p\n", str);
// for(int i = 0 ;i < argc; i++)
// {
// printf("argv[%d]: %p\n", i, argv[i]);
// }
// for(int i = 0; env[i]; i++)
// {
// printf("env[%d]: %p\n", i, env[i]);
// }
// return 0;
//}
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int g_val = 0;
int main()
{
 pid_t id = fork();
 if(id < 0){
 perror("fork");
 return 0;
 }
 else if(id == 0){ //child,⼦进程肯定先跑完，也就是⼦进程先修改，完成之后，⽗进程再读取 
 g_val=100;
 printf("child[%d]: %d : %p\n", getpid(), g_val, &g_val);
 }else{ //parent
 sleep(3);
 printf("parent[%d]: %d : %p\n", getpid(), g_val, &g_val);
 }
 sleep(1);
 return 0;
}


